import 'babel-polyfill';
import dva from 'dva';
import dynamic from "dva/dynamic";
import { Route, Router, Switch } from "dva/router";
import { createBrowserHistory } from 'history';
import '../index.less';
import global from '../models/global';

// 1. Initialize
const app = dva({
  history: createBrowserHistory()
});

// 2. Plugins
// app.use({});

// 3. Model
app.model(global);

function router({ history, app }) {
  const ShortUrl = dynamic({
    app,
    component: () => import('../routes/shorturl/ShortUrl'),
    models: () => [import('../models/shorturl')]
  });
  return (
    <Router history={history}>
      <Switch>
        <Route path="/" component={ShortUrl} />
      </Switch>
    </Router>
  );
}

// 4. Router
app.router(router);

// 5. Start
app.start('#root');
